﻿using System.Collections.Generic;
using Buca.Application.aBigTime.Model.BusinessObjects.Dictionary;
using Buca.Application.aBigTime.Presenter.Dictionary.Account;
using Buca.Application.aBigTime.View.Dictionary;
using Buca.Application.aBigTime.WindowsForm.FormBase;
using Buca.Application.aBigTime.WindowsForm.FormBase.PropertyGrid;

namespace Buca.Application.aBigTime.WindowsForm.FormDictionary
{
    public partial class FrmAccountList : FrmBaseTreeList, IAccountsView
    {
        private AccountsPresenter _accountsPresenter;

        public IList<AccountModel> Accounts
        {
            set
            {
                treeMain.DataSource = value;

                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccountCode", ColumnCaption = "Mã tài khoản", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccountName", ColumnCaption = "Tên tài khoản", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 300 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnCaption = "Mô tả", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsSystem", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnVisible = false });
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmBudgetSourcePropertyList"/> class.
        /// </summary>
        public FrmAccountList()
        {
            InitializeComponent();
            _accountsPresenter = new AccountsPresenter(this);
        }

        protected override void LoadDataIntoTree()
        {
            _accountsPresenter.Display();
        }

        protected override void DeleteTree()
        {
            new AccountPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }
    }
}
